#include <Lucnx/vsprintf.h>
#include <Lucnx/string.h>
#include <Lucnx/device.h>

static char buf[1024];

size_t printk(const char *fmt, ...)
{
    memset(buf, 0, sizeof(buf));

    va_list ap;
    va_start(ap, fmt);

    int i = vsprintf(buf, fmt, ap);

    va_end(ap);

    dev_t dev = device_search("tty");
    device_write(dev, NULL, buf, i);

    return i;
}

void putchk(char ch)
{
    dev_t dev = device_search("tty");
    device_write(dev, NULL, &ch, 1);
}

void pad_print(char *buf, int nr)
{
    int spaces = nr - strlen(buf);
    printk(buf);
    for (size_t i = 0; i < spaces; i++)
    {
        putchk(' ');
    }
}
